#include <iostream>
using namespace std;

/*
    【题目238】对Point类重载++（自增）、“-（自减）运算符。
    【题目240】定义Point类，有成员变量X、Y，为其定义友元函数实现重载+。
*/

class Point
{
public:
    Point(int x = 0, int y = 0) : x(x), y(y) {}

    Point operator++(int)
    {
        Point temp = *this;
        this->x++;
        this->y++;
        return temp;
    }

    Point operator++()
    {
        this->x++;
        this->y++;
        return *this;
    }

    Point operator--(int)
    {
        Point temp = *this;
        this->x--;
        this->y--;
        return temp;
    }

    Point operator--()
    {
        this->x--;
        this->y--;
        return *this;
    }

    Point operator+(const Point &p)
    {
        Point temp;
        temp.x = this->x + p.x;
        temp.y = this->y + p.y;
        return temp;
    }

    Point operator-(const Point &p)
    {
        Point temp;
        temp.x = this->x - p.x;
        temp.y = this->y - p.y;
        return temp;
    }

    void show()
    {
        cout << "(" << x << "," << y << ")" << endl;
    }

    friend ostream &operator<<(ostream &os, Point &p)
    {
        os << "(" << p.x << "," << p.y << ")";
        return os;
    }

private:
    int x, y;
};

int main()
{
    Point p(1, 2);
    p.show();
    Point p1 = p++;
    cout << "p1: " << p1 << endl;
    cout << p << endl;
    ++p;
    cout << p << endl;
    p--;
    cout << p << endl;

    p1 = p + p;
    cout << "p1: " << p1 << endl;
    p1 = p - p;
    cout << "p1: " << p1 << endl;
}